﻿/*
 * Twipler - Twitter Web Client with features.
 *  
 *  Copyright (C) 2009, 2010. Ian Quigley
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details. 
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

using System.Collections.Generic;
using Twipler.Data.Access;
using Twipler.Data.Entity.Twipler;

namespace Twipler.App
{
    public class Config
    {
        public static string ConsumerKey;
        public static string ConsumerSecret;

    	private static readonly Dictionary<string, string> AppSettings;

        static Config()
        {
			AppSettings = new Dictionary<string, string>();

            ConsumerKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"];
            ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];            
        }

        public static int DefaultDesignId()
        {
            return Factory.Setting.GetSettingInt("DefaultDesignId", SettingType.ApplicationInternal, 0);
        }

        public static int DefaultStyleId()
        {
            return Factory.Setting.GetSettingInt("DefaultStyleId", SettingType.ApplicationInternal, 0);
        }

        public static int DefaultVisitorType()
        {
            return Factory.Setting.GetSettingInt("DefaultVisitorType", SettingType.ApplicationInternal, (int)VisitorRole.Registered);
        }

        public static int UtcSecondsOffset()
        {
        	return int.Parse(Setting("UtcSecondsOffset", "0"));
        }
        
		public static string Setting(string key, string defaultValue)
		{
			if (AppSettings.ContainsKey(key))
				return AppSettings[key];

			string val = Factory.Setting.GetSetting(key, SettingType.ApplicationInternal);
			if (val == null)
				return defaultValue;

			AppSettings.Add(key, val);

			return val;
		}

        private static bool? _isLoggingEnabled;
        public static bool IsLoggingEnabled
        {
            get
            {
                if (App.Current.NHibConfig == null)
                     return true;

                if (_isLoggingEnabled.HasValue == false)
                    _isLoggingEnabled = Factory.Setting.GetSettingBool("LoggingEnabled", SettingType.ApplicationInternal, false);

                return _isLoggingEnabled.Value;
            }

            set
            {
                _isLoggingEnabled = value;
            }
        }
    }
}